package example.demo.juc;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

@Slf4j
public class SyncInterruptTest {
    public static final Object lock = new Object();

    public static void demo(){
        Thread main = Thread.currentThread();
        synchronized (lock){
            new Thread(()->{
                synchronized (lock){
                    main.interrupt();
                    try {
                        log.info("打断main");
                        TimeUnit.SECONDS.sleep(Integer.MAX_VALUE);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            try {
                lock.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) throws InterruptedException {
        demo();
        /*Thread main = Thread.currentThread();
        new Thread(() -> {
            synchronized (lock) {
                try {
                    TimeUnit.SECONDS.sleep(4);
                    main.interrupt();
                    log.info("打断--mian线程");
                    TimeUnit.SECONDS.sleep(Integer.MAX_VALUE);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "aaa").start();
        TimeUnit.SECONDS.sleep(2);
        synchronized (lock) {
            log.info("wahahah");
        }*/
    }
}
